|
|
|
|
|
|
|
If your computer uses color palettes, you can use palette animation to make fades extremely fast. Use the SetPaletteEntries API function to make the image's palette colors darker and darker until they are all black. An 8-bit color image has only 256 colors in its color palette. For a large image, updating the 256 values is much faster than updating the colors of each pixel individually. For example, a 200 by 200 pixel image contains 40,000 pixels. Setting the values of 40,000 pixels takes much longer than updating 256 palette entries. |
|
|
|
|
|
|
|
|
Unfortunately, palette animation does not work if you are not using color palettes. If you are using 16- or 24-bit color, you must update each of the pixels individually. Example program Fade does this to produce fading animation sequences. |
|
|
|
|
|
|
|
|
Screen savers were originally created to protect computer monitors. If the contents of a screen did not change for a very long time, the images being displayed might burn the phosphors on the screen, leaving a ghostly picture as a permanent addition to the monitor. A screen saver either blanks the screen so that there is no image to burn in or displays a series of moving images. By keeping the images moving, the program ensures that nothing stays in one place long enough to burn the phosphors. Today, screen savers are used more for entertainment than to protect monitors. |
|
|
|
|
|
|
|
|
Screen savers are executable programs much like any other. One thing that makes them seem different is that they have a .scr extension instead of ending in .exe. This is just a naming convention, and you can simply rename your executable screen saver so that it has a .scr extension. |
|
|
|
|
|
|
|
|
The program must also handle a few screen saver details. When Windows starts a screen saver, it passes it command line arguments telling it how to run. These arguments include: |
|
|
|
|
|
|
|
|
/c The program should display its configuration screen. |
|
|
|
|
|
|
|
|
/s The program should run as a normal screen saver. |
|
|
|
|
|
|
|
|
/p The program should display a preview. |
|
|
|
|
|
|
|
|
To capture those arguments, you should start your program with a subroutine named Main in a .bas module instead of with a startup form. Use the Command$ function to see what arguments were passed to the program. |
|
|
|
|
|
|
|
|
If the program sees the /c flag, it should display a configuration form to allow the user to tell it how to run. For example, a bouncing ball program might let the user decide the number of balls to display. If the user accepts the new values, the form should save the values to the registry so that it can read the values later when it must run as a screen saver. |
|
|
|
|
|
|
|
|
If the program receives the /s flag, it should run as a normal screen saver. |
|
|
|
|
|
|
|
|
The strangest case occurs when the program receives the /p flag. In that case, the program should display a preview of the screen saver as shown in Figure 9.13. |
|
|
|
|
|